package basic.socket.chat;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

/**
 * @author bingo
 * @Description
 * @Date 2018/7/20
 */
public class Server {

    private List<ServerThread> threads = new ArrayList<>();

    public void run(){
        try {
            ServerSocket serverSocket = new ServerSocket(8888);
            System.out.println("服务器已经启动！等待连接。。。。。。");

            int i= 0;
            while (true){
                i++;
                Socket socket = serverSocket.accept();
                System.out.println("第"+i+"客户端");

             /*  UserDao userDao = new UserDao();
                userDao.insert();*/
                ServerThread serverThread = new ServerThread(socket,threads);
                Thread thread = new Thread(serverThread);
                threads.add(serverThread);
                thread.start();

            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {

        Server server = new Server();
        server.run();
    }

}
